package com.allwees.bs.module.oms.service.impl;

import com.allwees.bs.core.model.order.wf.refund.ERefundAction;
import com.allwees.bs.module.oms.entity.OrderRefund;
import com.allwees.bs.module.oms.req.OrderRefundAuditReq;
import com.allwees.bs.module.oms.service.PlatformOrderRefundService;
import com.allwees.core.common.constant.EStatus;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * 平台订单退货
 *
 * @author mouhaining
 * @since
 */
@Service
public class PlatformOrderRefundServiceImpl extends BaseOrderRefundServiceImpl implements PlatformOrderRefundService {
	@Override
	@Transactional
	public void audit(OrderRefundAuditReq req) {
		OrderRefund orderRefund = checkByUuid(req.getUuid());

		ERefundAction refundAction = ERefundAction.PLATFORM_AUDIT_REFUND_REJECT;
		EStatus status = EStatus.OMS_REFUND_REJECT;
		if(req.isApproved()) {
			refundAction = ERefundAction.PLATFORM_AUDIT_REFUND_ACCEPT;
			status = EStatus.OMS_REFUND;
		}
		orderRefund.signal(refundAction);
		orderRefund.setEStatus(status);
		updateByUuid(orderRefund);

		generalOmsOrderItemService.doRefunded(orderRefund.getOrderItemUuid(), req.isApproved());
		generalOmsOrderService.doRefunded(orderRefund.getOrderUuid(),orderRefund.getOrderItemUuid());
	}
}
